﻿/*
* ---------------------------------------------------
* 作者: MTQ 
* 日期： 2021/5/14 14:28:20 
* ---------------------------------------------------
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MTQ.BLL.UploadExcel;
using System.Web;
using NPOI.SS.UserModel;
using MTQ.Model;
using MTQ.BLL;
using MTQ.IBLL;
using MTQ.Common;
using System.Data;
namespace MTQ.BLL
{
    public partial class Log_WebService : BaseService<Log_Web>
    {
        public IQueryable<Log_Web> LoadSearchData(Log_WebQuery query)
        {
            var temp = _DbSession.Log_WebRepository.LoadEntities(u => true);
            //可根据所需查询条件自行添加  

            if (!string.IsNullOrEmpty(query.Log_UserId))
            {
                temp = temp.Where<Log_Web>(u => u.Log_UserId.Contains(query.Log_UserId));
            }

            if (!string.IsNullOrEmpty(query.Log_UserName))
            {
                temp = temp.Where<Log_Web>(u => u.Log_UserName.Contains(query.Log_UserName));
            }

            if (!string.IsNullOrEmpty(query.Log_Path))
            {
                temp = temp.Where<Log_Web>(u => u.Log_Path.Contains(query.Log_Path));
            }

            if (!string.IsNullOrEmpty(query.Log_Remark))
            {
                temp = temp.Where<Log_Web>(u => u.Log_Remark.Contains(query.Log_Remark));
            }


            query.Total = temp.Count();
            return temp.OrderBy(u => u.Log_Id).Skip(query.PageSize * (query.PageIndex - 1)).Take(query.PageSize);
        }
        protected override IQueryable<Log_Web> GetBootstrapQueryable<K>(K paramterquery)
        {
            Log_WebQuery query = paramterquery as Log_WebQuery;
            IQueryable<Log_Web> temp = _DbSession.Log_WebRepository.LoadEntities(u => true);


            if (!string.IsNullOrEmpty(query.Log_UserId))
            {
                temp = temp.Where<Log_Web>(u => u.Log_UserId.Contains(query.Log_UserId));
            }

            if (!string.IsNullOrEmpty(query.Log_UserName))
            {
                temp = temp.Where<Log_Web>(u => u.Log_UserName.Contains(query.Log_UserName));
            }

            if (!string.IsNullOrEmpty(query.Log_Path))
            {
                temp = temp.Where<Log_Web>(u => u.Log_Path.Contains(query.Log_Path));
            }

            if (!string.IsNullOrEmpty(query.Log_Remark))
            {
                temp = temp.Where<Log_Web>(u => u.Log_Remark.Contains(query.Log_Remark));
            }


            return temp;
        }

        public IQueryable<Log_Web> GetIQueryable(Log_WebQuery query)
        {
            return this.GetBootstrapQueryable<Log_WebQuery>(query);
        }
        public static bool ReadExcel(string filename, Guid userid, ref string msg)
        {
            return true;
        }


        public static void SaveRequestLog(HttpRequestBase httpRequest, string UserName)
        {

            try
            {
                Log_Web log_web = new Log_Web()
                {
                    Log_UserName = UserName,
                    Log_CreateTime = System.DateTime.Now,
                    Log_Path = httpRequest.FilePath.ToString(),
                    //Log_Remark = httpRequest.QueryString.ToString(),
                    Log_HttpMethod = httpRequest.HttpMethod,

                };
                try
                {
                   
                   //log_web.Log_QueryString = httpRequest.QueryString;
                    
                   
                }
                catch { }

                new Log_WebService().AddEntity(log_web);
            }
            catch(Exception ex) {
                LogManager.WriteLog("日志异常",ex);
            }
        }

    }
}

